package com.hx.springboot1.controller;

import com.github.pagehelper.PageInfo;
import com.hx.springboot1.pojo.entity.TabTeacher;
import com.hx.springboot1.service.TeacherService;
import com.hx.springboot1.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Author: hx
 * Date: 2021-05-22 22/47
 * Description: Nothing else
 */
@Controller
public class TeacherController {
    @Autowired
    TeacherService teacherService;
    @RequestMapping("/selectTeacher")
    public String selectTeacher(String searchName, String pageNum, String pageSize, Model model){
        PageInfo pageInfo = teacherService.selectAllTeacher(searchName, pageNum, pageSize);
        model.addAttribute("pageInfo",pageInfo);
        return "manage/teacherList";
    }
    @PostMapping("/insertOrUpdateTeacher")
    public String iouTeacher(Model model,Integer teacherId,Integer userId,
                             Integer collegeId,String teacherName,String teacherSex,String teacherJob,String teacherQua,String teacherBorn){
        teacherService.insertOrUpdateTeacher(teacherId,userId,
                collegeId,teacherName,teacherSex,teacherJob,teacherQua,teacherBorn);
        return this.selectTeacher(null,"1","5",model);
    }
    @GetMapping("/selectTeacherById")
    @ResponseBody
    public TabTeacher sTbI(Integer id){
        return teacherService.selectTeacherById(id);
    }
    @GetMapping("/deleteTeacherInfo")
    @ResponseBody
    public ResultMsg deleteTeacher(String TIDAndUID){
        return teacherService.delTeacher(TIDAndUID);
    }
}
